<?php

namespace App\Http\Requests;

use App\Http\Requests\BaseFormRequest;
use Illuminate\Validation\Rule;

class SubtypeRequest extends BaseFormRequest
{
    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
        return true;
    }

    public function scenes()
    {
        $mid = $this->input('ts_Maintypeid');

        return [
            'store'=>[
                'ts_Maintypeid' => 'required|integer|exists:t_devicetype,dt_typeid',
				'ts_typeid' => [
                    'required',
                    'integer',
                    Rule::unique('t_Subdevicetype', 'ts_typeid')
                    ->where(function ($query) use($mid){
                        return $query->where('ts_Maintypeid', $mid);
                    }),
                ],
				'ts_TypeMo' => 'required|max:60',
				'ts_Icon' => 'required|max:60',
			],
			'update'=>[
                'ts_Maintypeid' => 'required|integer|exists:t_devicetype,dt_typeid',
				'ts_typeid' => [
                    'required',
                    'integer',
                    Rule::unique('t_Subdevicetype', 'ts_typeid')
                    ->ignore($this->input('ts_index'), 'ts_index')
                    ->where(function ($query) use($mid){
                        return $query->where('ts_Maintypeid', $mid);
                    }),
                ],
				'ts_TypeMo' => 'required|max:60',
				'ts_Icon' => 'required|max:60',
			]
        ];
    }
	
	public function messages()
    {
        return [
			'ts_typeid.required' => '子类编号必须',
            'ts_typeid.integer' => '子类编号必须是数字',
            'ts_typeid.unique' => '子类编号存在重复, 重新输入',
            
			'ts_TypeMo.required' => '子类名称必须',
            'ts_TypeMo.max' => '子类名称不能超过60个字符',
            
            'ts_Icon.required' => '子类图标必须',
			'ts_Icon.max' => '子类图标不能超过60个字符',
            
			'ts_Maintypeid.required' => '设备分类编号必须',
			'ts_Maintypeid.integer' => '设备分类编号必须是数字',
            'ts_Maintypeid.exists' => '设备分类不存在',
            
        ];
    }
	
	public function withValidator($validator)
	{

	}
}
